package com.ccx.web.backand;

import com.ccx.model.EbComment;
import com.ccx.service.EbCommentService;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("/comment")
public class EbCommentController {

    @Autowired
    EbCommentService ebCommentService;

    //显示分页
    @RequestMapping("/list")
    public String selectComment(Model model, @RequestParam(value = "page",defaultValue = "1") Integer page, @RequestParam(value = "pageSize",defaultValue = "1") Integer paeSize){

        List<EbComment> ebComments = ebCommentService.pageTest(page, paeSize);
        model.addAttribute("ebComment",ebComments);

        model.addAttribute("page",page);
        model.addAttribute("maxPage",((Page)ebComments).getPages());
        return "manage/guestbook";
    }

    //查询回复信息
    @RequestMapping("/to_edit")
    public String selectComment(Model model,@RequestParam("ecId") Integer ecId){
        EbComment ebComment = ebCommentService.selectById(ecId);
        model.addAttribute("ebComment",ebComment);
        return "manage/guestbook-modify";
    }

    //修改回复信息
    @RequestMapping("/update")
    public String updateComent(EbComment ebComment){
        int i = ebCommentService.updateTest(ebComment);
        if(i<1){
            return "manage/manage-error";
        }
        return "manage/manage-result";
    }

    //删除回复信息
    @RequestMapping("/delete")
    public String deleteComment(@RequestParam("ecId") Integer ecId){
        int i = ebCommentService.deleteTest(ecId);
        if(i<1){
            return "manage/manage-error";
        }
        return "manage/manage-result";
    }
}

